package linker;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashSet;
import java.util.Properties;

import data.Statement;
import data.URI;

public class Counter {
	private HashSet<String> lcounter;
	private HashSet<String> ocounter;
	public Counter() {
		lcounter= new HashSet<String>();
		ocounter= new HashSet<String>();
	}
	

	
	public void addl(URI uri){
		if(!lcounter.contains(uri.getSurfix()))
		lcounter.add(uri.getSurfix());
	}
	public void addo(URI uri){
		if(!ocounter.contains(uri.getSurfix()))
		ocounter.add(uri.getSurfix());
	}

	public void show()
	{
		System.out.println("objects: "+ocounter.size());
		System.out.println("locations: "+lcounter.size());

	}
	
	public static void main(String[] args) {
		
		if (args.length < 1) {
			System.out
					.println("please specify the path for config file as parameter");
			return;

		}
		String config = args[0];
		Properties pre = new Properties();
		try {
			pre.load(new FileInputStream(config));
		} catch (FileNotFoundException e) {
			System.out.println("cannot find config file");
			return;
		} catch (IOException e) {
			System.out.println("cannot open config file");
			return;
		}

		String input = pre.getProperty("input");

		

		Counter counter = new Counter();

		Parser par = new Parser(null);
		try {
			par.open(input);
		} catch (FileNotFoundException e) {
			System.out.println("cannot find input file");
			return;
		} catch (IOException e) {
			System.out.println("cannot open input file");
			return;
		}
		
		
		System.out.println("processing...");

		while (par.hasNext()) {
		Statement s= par.nextStatement();
		counter.addo(s.getSubject());
		counter.addo(s.getObject());
		}
		counter.show();
		System.out.println("linking complete");
	}
}